import normal
import global_param
import sys
import os


def less_than_ten(x):
    if x < 10:
        return True
    return False


if __name__ == "__main__":
    print('---修改文件名日期---')
    today = normal.get_time(1)
    print('Today is :[', today, ']')
    word_excel_type = ('.doc', '.docx', '.xls')
    root_path = global_param._global_dict['root_path']
    file_list = normal.get_directed_file(root_path, word_excel_type)
    # print(file_list)
    for file in file_list:
        year_index = file.find('年')
        month_index = file.find('月')
        day_index = file.find('日')

        # 日期相同退出执行，否则继续
        if year_index != -1:
            file_month = int(file[year_index + 1:month_index])
            file_day = int(file[month_index + 1:day_index])

            year = int(today[:4])
            second_point_index = today[5:].find('.') + 5
            month = int(today[5:second_point_index])
            day = int(today[second_point_index+1:])
            if (file_month == month) & (file_day == day):
                print('File name is same as today')
                sys.exit()
            new_name = file[:year_index - 4] + str(year) + '年' + str(month) + '月' + str(day) + '日' + \
                       file[day_index + 1:]
            file_path = root_path + file
            new_path = root_path + new_name
            os.renames(file_path, new_path)
    print('---完成文件名日期修改---')
